package uk.co.cocking.getinline2.restlet;

import org.restlet.Restlet;
import org.restlet.data.MediaType;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.data.Status;

import uk.co.cocking.getinline2.pipeline.io.CouldNotProcessRecordException;


public class StringSourceRestlet extends Restlet {
	private StringRestRequester client = new StringRestRequester("http://localhost:8183/");
	
	public StringSourceRestlet() {
		
	}

	public void handle(Request request, Response response) {
		String query = request.getResourceRef().getQuery();
		if (query != null) {
			response.setEntity("bar", MediaType.TEXT_PLAIN);
			try {
				client.transform("bar?bar");
			} catch (CouldNotProcessRecordException e) {
				e.printStackTrace();
			}
		} else {
			response.setStatus(Status.CLIENT_ERROR_FORBIDDEN);
			response.setEntity("Naughty, naughty!", MediaType.TEXT_PLAIN);
		}
		
	}
	
}

